package com.zb.zeus.common.core.utils;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.Nullable;

import java.util.Objects;

/**
 * @author fujianjian
 * @since 2021/7/5 9:38
 */
public class Func {
    public static String toStr(Object str) {
        return toStr(str, "");
    }

    public static String toStr(Object str, String defaultValue) {
        return null == str ? defaultValue : String.valueOf(str);
    }

    public static boolean isBlank(@Nullable final CharSequence cs) {
        return StringUtils.isBlank(cs);
    }

    public static boolean isNotBlank(@Nullable final CharSequence cs) {
        return StringUtils.isNotBlank(cs);
    }

    public static boolean containsAny(CharSequence str, CharSequence... testStrs) {
        return null != getContainsStr(str, testStrs);
    }

    public static String getContainsStr(CharSequence str, CharSequence... testStrs) {
        if (!StringUtils.isEmpty(str) && !ArrayUtils.isEmpty(testStrs)) {
            CharSequence[] var2 = testStrs;
            int var3 = testStrs.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                CharSequence checkStr = var2[var4];
                if (str.toString().contains(checkStr)) {
                    return checkStr.toString();
                }
            }

            return null;
        } else {
            return null;
        }
    }

    public static String upperFirst(String str) {
        char firstChar = str.charAt(0);
        if (firstChar >= 'a' && firstChar <= 'z') {
            char[] arr = str.toCharArray();
            arr[0] = (char)(arr[0] - 32);
            return new String(arr);
        } else {
            return str;
        }
    }

    public static boolean equals(Object obj1, Object obj2) {
        return Objects.equals(obj1, obj2);
    }

}
